﻿using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace ComponentEngine_12_12_2014 {

	public struct Entity {

		public int Index;
		public string Name;
		public bool IsActive;
		public Vector2 Position;
		public GeneralState GeneralState;

		//=====( Begin Components )==============

		#region Components

		// Mind: Depends[]
		public bool HasMind;
		public MindType MindType; // [None, Enemy]

		// Movement: Depends[Position]
		public bool HasMovement;
		public MovementState MovementState; // [Idle, Walking, Running]
		public float Speed;
		public HorizontalDirection HorizontalDirection; // [Right, Left]

		// Animation: Depends[N/A] // Must be the last component called in Update.
		public bool HasAnimation;
		public Dictionary<GeneralState, Animation> GeneralStateAnimations;
		public Animation Animation;

		// Appearance: Depends[N/A]
		public bool HasAppearance;
		public Texture2D Texture;
		public Color Color;
		public float Rotation;
		public Vector2 Origin;
		public SpriteEffects SpriteEffects;

		#endregion

		//=====( End Components )================

		public void Update() {
			if (!IsActive) {
				return;
			}

			if (HasMind) {
				Behaviors.Think(ref this);
			}

			if (HasMovement) {
				Behaviors.Move(ref this);
			}

			if (HasAnimation) {
				Behaviors.Animate(ref this);
			}
		}

		public void Draw() {
			if (!IsActive) {
				return;
			}

			if (HasAppearance) {
				MyGame.SpriteBatch.Draw(Texture, Position, null, Color, Rotation, Origin, 1, SpriteEffects, 0);
			}
		}

	}

}